package demo08;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@ComponentScan("demo08")
@PropertySource("classpath:config.properties")
@Configuration
public class Config {
    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Value("${spring.datasource.username}")
    private String dbUsername;

    @Value("${spring.datasource.password}")
    private String dbPassword;
    @Bean
    public Student initStudent(){
        return new Student();
    }
    @Bean
    public DruidDataSource initDruidDataSource(){
        DruidDataSource ds = new DruidDataSource();
        ds.setUrl(dbUrl);
        ds.setUsername(dbUsername);
        ds.setPassword(dbPassword);
        ds.setInitialSize(5);
        ds.setMaxActive(30);
        return ds;
    }

}
